package com.hopu.haogoumall.db.mapper;

import com.hopu.haogoumall.db.dto.GrouponRulesDto;
import com.hopu.haogoumall.db.module.HaogoumallGroupon_Rules;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

@Mapper
public interface HaogoumallGroupon_RulesMapper {
    @Delete({
        "delete from haogoumall_groupon_rules",
        "where groupon_rules_id = #{grouponRulesId,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer grouponRulesId);

    @Insert({
        "insert into haogoumall_groupon_rules (groupon_rules_id, goods_id, ",
        "goods_name, goods_pic_url, ",
        "discount_money, discount_member, ",
        "expire_time, groupon_rules_status, ",
        "groupon_rules_add_time, groupon_rules_update_time, ",
        "groupon_rules_deleted)",
        "values (#{grouponRulesId,jdbcType=INTEGER}, #{goodsId,jdbcType=INTEGER}, ",
        "#{goodsName,jdbcType=VARCHAR}, #{goodsPicUrl,jdbcType=VARCHAR}, ",
        "#{discountMoney,jdbcType=DECIMAL}, #{discountMember,jdbcType=INTEGER}, ",
        "#{expireTime,jdbcType=TIMESTAMP}, #{grouponRulesStatus,jdbcType=SMALLINT}, ",
        "#{grouponRulesAddTime,jdbcType=TIMESTAMP}, #{grouponRulesUpdateTime,jdbcType=TIMESTAMP}, ",
        "#{grouponRulesDeleted,jdbcType=BIT})"
    })
    int insert(HaogoumallGroupon_Rules record);

    @InsertProvider(type=HaogoumallGroupon_RulesSqlProvider.class, method="insertSelective")
    int insertSelective(HaogoumallGroupon_Rules record);

    @Select({
        "select",
        "groupon_rules_id, goods_id, goods_name, goods_pic_url, discount_money, discount_member, ",
        "expire_time, groupon_rules_status, groupon_rules_add_time, groupon_rules_update_time, ",
        "groupon_rules_deleted",
        "from haogoumall_groupon_rules",
        "where groupon_rules_id = #{grouponRulesId,jdbcType=INTEGER}"
    })
    @Results(id = "grouponResult" ,value = {
        @Result(column="groupon_rules_id", property="grouponRulesId", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="goods_id", property="goodsId", jdbcType=JdbcType.INTEGER),
        @Result(column="goods_name", property="goodsName", jdbcType=JdbcType.VARCHAR),
        @Result(column="goods_pic_url", property="goodsPicUrl", jdbcType=JdbcType.VARCHAR),
        @Result(column="discount_money", property="discountMoney", jdbcType=JdbcType.DECIMAL),
        @Result(column="discount_member", property="discountMember", jdbcType=JdbcType.INTEGER),
        @Result(column="expire_time", property="expireTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="groupon_rules_status", property="grouponRulesStatus", jdbcType=JdbcType.SMALLINT),
        @Result(column="groupon_rules_add_time", property="grouponRulesAddTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="groupon_rules_update_time", property="grouponRulesUpdateTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="groupon_rules_deleted", property="grouponRulesDeleted", jdbcType=JdbcType.BIT)
    })
    HaogoumallGroupon_Rules selectByPrimaryKey(Integer grouponRulesId);

    @UpdateProvider(type=HaogoumallGroupon_RulesSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(HaogoumallGroupon_Rules record);

    @Update({
        "update haogoumall_groupon_rules",
        "set goods_id = #{goodsId,jdbcType=INTEGER},",
          "goods_name = #{goodsName,jdbcType=VARCHAR},",
          "goods_pic_url = #{goodsPicUrl,jdbcType=VARCHAR},",
          "discount_money = #{discountMoney,jdbcType=DECIMAL},",
          "discount_member = #{discountMember,jdbcType=INTEGER},",
          "expire_time = #{expireTime,jdbcType=TIMESTAMP},",
          "groupon_rules_status = #{grouponRulesStatus,jdbcType=SMALLINT},",
          "groupon_rules_add_time = #{grouponRulesAddTime,jdbcType=TIMESTAMP},",
          "groupon_rules_update_time = #{grouponRulesUpdateTime,jdbcType=TIMESTAMP},",
          "groupon_rules_deleted = #{grouponRulesDeleted,jdbcType=BIT}",
        "where groupon_rules_id = #{grouponRulesId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(HaogoumallGroupon_Rules record);


    /** 查询所有团购信息*/
    @Select("select B.groupon_rules_id,A.goods_id,B.goods_pic_url,A.goods_name,B.discount_member,B.expire_time,B.groupon_rules_status,B.groupon_rules_deleted,B.groupon_rules_add_time,B.groupon_rules_update_time,A.goods_brief,A.goods_retail_price,B.discount_money from haogoumall_goods A,haogoumall_groupon_rules B where A.goods_id = B.goods_id")
    List<GrouponRulesDto> findGrouponInfo();
}